package com.crayon2f.test;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by feifan.gou@gmail.com on 2020/12/28 16:03.
 */
public class HashMapSource {


    @Test
    public void hash() {

        String string = "111";
        int i = string.hashCode();
        System.out.println(i);
        System.out.println(i ^ i >>> 16);
        Map<String, Integer> map = new HashMap<>();
        map.put(string, 3);
        System.out.println(map);
    }

    static int tableSizeFor(int cap) {
        int n = cap - 1;
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        return (n < 0) ? 1 : (n >= (1 << 30)) ? (1 << 30) : n + 1;
    }

    @Test
    public void testTableSizeFor() {


        System.out.println(tableSizeFor(14));
    }
}
